import os
import cv2
from numpy import *
import numpy as np

img = "./dog_bike_car_320x320.jpg"
output = "./dog_bike_car_320x320.bgr"

def png2bgr(img, output):
    img_cv2 = cv2.imread(img)
    shape = img_cv2.shape
    print(shape)  # [w, h, 3]
    
    (B, G, R) = cv2.split(img_cv2)
    with open (output, 'wb') as fp:
        for i in range(320):
            for j in range(320):
                fp.write(B[i, j])
        for i in range(320):
            for j in range(320):
                fp.write(G[i, j])
        for i in range(320):
            for j in range(320):
                fp.write(R[i, j])

    print("done")

png2bgr(img, output)